package com.yun.zf.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.zf.admin.mapper.ZfHouseInfoSaleMapper;
import com.yun.zf.admin.service.ZfHouseInfoSaleService;
import com.yun.zf.common.app.domain.ZfHouseInfoSale;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 房屋出售维护表 服务实现类
 * </p>
 *
 * @author cj
 * @since 2021-03-09
 */
@Service
public class ZfHouseInfoSaleServiceImpl extends ServiceImpl<ZfHouseInfoSaleMapper, ZfHouseInfoSale> implements ZfHouseInfoSaleService {

    @Override
    public ZfHouseInfoSale addHouseInfoSale(ZfHouseInfoSale houseInfoSale) {
         baseMapper.insert(houseInfoSale);
         return  houseInfoSale;
    }

    @Override
    public ZfHouseInfoSale motifyHouseInfoSale(ZfHouseInfoSale houseInfoSale) {
        QueryWrapper<ZfHouseInfoSale> saleQueryWrapper = new QueryWrapper<>();
        saleQueryWrapper.lambda().eq(ZfHouseInfoSale::getCityCode,houseInfoSale.getCityCode())
                .eq(ZfHouseInfoSale::getProvinceCode,houseInfoSale.getProvinceCode())
                .eq(ZfHouseInfoSale::getBasicId,houseInfoSale.getBasicId()).orderByAsc(ZfHouseInfoSale::getCreateTime);
        ZfHouseInfoSale sale = baseMapper.selectList(saleQueryWrapper).get(0);
        BeanUtil.copyProperties(houseInfoSale,sale);
         baseMapper.update(sale,saleQueryWrapper);
        return sale;
    }

    @Override
    public ZfHouseInfoSale getHouseInfoSale(Long basicId, Long provinceCode, Long cityCode) {
        QueryWrapper<ZfHouseInfoSale> saleQueryWrapper = new QueryWrapper<>();
        saleQueryWrapper.lambda().eq(ZfHouseInfoSale::getCityCode,cityCode)
                .eq(ZfHouseInfoSale::getProvinceCode,provinceCode)
                .eq(ZfHouseInfoSale::getBasicId,basicId);
        return baseMapper.selectOne(saleQueryWrapper);
    }
}
